package com.googlecode.ozonbooksfinder.matefinder.business
{
	import com.googlecode.ozonbooksfinder.domain.Book;
	import com.googlecode.ozonbooksfinder.parser.BooksParser;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.collections.ArrayCollection;

	public class BooksManager extends EventDispatcher
	{
		private var _books:ArrayCollection;
		[Bindable(event="booksChange")]
		public function get books ():ArrayCollection
		{
			return _books;
		}

		public function setRawBooks (result:Object):void
		{
			_books = BooksParser.parseSearchResult(result);
			dispatchEvent (new Event ("booksChange"));
		}
		
		public function processBookDetails (targetBook:Book, result:Object):void
		{
			var book:Book = BooksParser.parseItemDetail (result);
			targetBook.addExtendedDetails(book);
		}
		
		public function processBookInfo (targetBook:Book, result:Object):void
		{
			var book:Book = BooksParser.parseItemInfo (result);
			targetBook.addExtendedDetails(book);
		}
	}
}